package com.chuanke.ckfamily.service.finance.impl.thread;

import com.chuanke.ckfamily.service.common.CacheService;
import com.chuanke.ckfamily.service.util.RedpacketUtil;

public class CreatePacketRunnable implements Runnable {

    private CacheService cacheService;

    private Long pid;

    private int num;

    private Long money;

    public CreatePacketRunnable(CacheService cacheService, Long pid, int num, Long money) {
        this.pid = pid;
        this.cacheService = cacheService;
        this.num = num;
        this.money = money;
    }

    @Override
    public void run() {
        for (int i = 0; i < num; i++) {
            Long itemMoney = RedpacketUtil.getRandonMoney(num, money);
            cacheService.leftPush(CacheService.KEY_PREFIX.packet_money_queue_.name() + pid, itemMoney);

            num--;
            money -= itemMoney;
        }
    }
}
